package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.system.bo.ParkLeaveQueryPriceVo;
import com.ruoyi.system.dto.ParkLeavePriceVo;
import com.ruoyi.system.vo.GangTingLeaveVo;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyParkLeaveVo;
import com.ruoyi.system.bo.ZsyyParkLeaveQueryBo;
import com.ruoyi.system.bo.ZsyyParkLeaveAddBo;
import com.ruoyi.system.bo.ZsyyParkLeaveEditBo;
import com.ruoyi.system.service.IZsyyParkLeaveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 车辆离场记录Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "车辆离场记录控制器", tags = {"车辆离场记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/parkLeave")
public class ZsyyParkLeaveController extends BaseController {

    private final IZsyyParkLeaveService iZsyyParkLeaveService;

    /**
     * 查询车辆离场记录列表
     */
    @ApiOperation("查询车辆离场记录列表")
    @PreAuthorize("@ss.hasPermi('system:parkLeave:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyParkLeaveVo> list(@Validated ZsyyParkLeaveQueryBo bo) {
        return iZsyyParkLeaveService.queryPageList(bo);
    }
    /**
     * 岗亭车辆进出场
     */
    @ApiOperation("岗亭车辆进出场")
    @PreAuthorize("@ss.hasPermi('system:parkLeave:gangtingList')")
    @GetMapping("/gangtingList")
    public TableDataInfo<GangTingLeaveVo> gangtingList(@Validated ZsyyParkLeaveQueryBo bo) {
        return iZsyyParkLeaveService.gangtingList(bo);
    }
    /**
     * 岗亭车辆进出场
     */
    @ApiOperation("放行记录")
	@PreAuthorize("@ss.hasPermi('system:parkLeave:leaveRecordList')")
    @GetMapping("/leaveRecordList")
    public TableDataInfo<ZsyyParkLeaveVo> leaveRecordList(@Validated ZsyyParkLeaveQueryBo bo) {
        return iZsyyParkLeaveService.leaveRecordList(bo);
    }

    /**
     * 导出车辆离场记录列表
     */
    @ApiOperation("导出车辆离场记录列表")
    @PreAuthorize("@ss.hasPermi('system:parkLeave:export')")
    @Log(title = "车辆离场记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyParkLeaveVo> export(@Validated ZsyyParkLeaveQueryBo bo) {
        List<ZsyyParkLeaveVo> list = iZsyyParkLeaveService.queryList(bo);
        ExcelUtil<ZsyyParkLeaveVo> util = new ExcelUtil<ZsyyParkLeaveVo>(ZsyyParkLeaveVo.class);
        return util.exportExcel(list, "车辆离场记录");
    }
    /**
     * 导出岗亭进出场记录列表
     */
    @ApiOperation("导出岗亭进出场记录列表")
    @PreAuthorize("@ss.hasPermi('system:parkLeave:exportGangTing')")
    @Log(title = "车辆离场记录", businessType = BusinessType.EXPORT)
    @GetMapping("/exportGangTing")
    public AjaxResult<GangTingLeaveVo> exportGangTing(@Validated ZsyyParkLeaveQueryBo bo) {
        List<GangTingLeaveVo> list = iZsyyParkLeaveService.exportGangTing(bo);
        ExcelUtil<GangTingLeaveVo> util = new ExcelUtil<GangTingLeaveVo>(GangTingLeaveVo.class);
        return util.exportExcel(list, "岗亭离场记录");
    }
    /**
     * 导出放行记录
     */
    @ApiOperation("导出放行记录")
    @PreAuthorize("@ss.hasPermi('system:parkLeave:exportLeaveRecord')")
    @Log(title = "放行记录", businessType = BusinessType.EXPORT)
    @GetMapping("/岗亭离场记录")
    public AjaxResult<ZsyyParkLeaveVo> exportLeaveRecord(@Validated ZsyyParkLeaveQueryBo bo) {
    	String sheetName = "";
    	if (bo.getIsType() == 1 ){
			sheetName = "优惠车记录";
		}
    	if (bo.getIsType() == 2 ){
			sheetName = "免费异常放行记录";
		}
    	if (bo.getIsType() == 3 ){
			sheetName = "手动放行记录";
		}
        List<ZsyyParkLeaveVo> list = iZsyyParkLeaveService.exportLeaveRecord(bo);
        ExcelUtil<ZsyyParkLeaveVo> util = new ExcelUtil<ZsyyParkLeaveVo>(ZsyyParkLeaveVo.class);
        return util.exportExcel(list, sheetName);
    }

    /**
     * 获取车辆离场记录详细信息
     */
    @ApiOperation("获取车辆离场记录详细信息")
    @PreAuthorize("@ss.hasPermi('system:parkLeave:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyParkLeaveVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyParkLeaveService.queryById(id));
    }
    /**
     * 获取停车离场的停车收费额
     */
    @ApiOperation("获取停车离场的停车收费额")
    @GetMapping("/getPriceTotal")
    public AjaxResult getPriceTotal(@Validated ParkLeaveQueryPriceVo priceVo) {
        return AjaxResult.success(iZsyyParkLeaveService.getPriceTotal(priceVo));
    }

    /**
     * 新增车辆离场记录
     */
    @ApiOperation("新增车辆离场记录")
    @PreAuthorize("@ss.hasPermi('system:parkLeave:add')")
    @Log(title = "车辆离场记录", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyParkLeaveAddBo bo) {
        return toAjax(iZsyyParkLeaveService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改车辆离场记录
     */
    @ApiOperation("修改车辆离场记录")
    @PreAuthorize("@ss.hasPermi('system:parkLeave:edit')")
    @Log(title = "车辆离场记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyParkLeaveEditBo bo) {
        return toAjax(iZsyyParkLeaveService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除车辆离场记录
     */
    @ApiOperation("删除车辆离场记录")
    @PreAuthorize("@ss.hasPermi('system:parkLeave:remove')")
    @Log(title = "车辆离场记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyParkLeaveService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
